def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def word_to_num(word):
    num_str = "zero one two three four five six seven eight nine"
    num_list = num_str.split()
    return num_list.index(word)

def num_to_prime(num):
    if is_prime(num):
        return num
    lower = num - 1
    upper = num + 1
    while True:
        if is_prime(lower):
            return lower
        elif is_prime(upper):
            return upper
        lower -= 1
        upper += 1

words = input().split()

if len(words) != 3:
    print("Wrong input")
else:
    num = word_to_num(words[0]) * 100 + word_to_num(words[1]) * 10 + word_to_num(words[2])
    if num < 100 or num > 999:
        print("Wrong input")
    else:
        result = num_to_prime(num)
        print(result)
